home *** CD-ROM | disk | FTP | other *** search
/ Netware Super Library / Netware Super Library.iso / pgm_tool / lu62 / comm / fcom.asm < prev    next >
Assembly Source File  |  1995-07-03  |  22KB  |  796 lines

  1. ;*******************************************************
  2. ;*                                                     *
  3. ;*     Asynchronous communication driver               *
  4. ;*           (for null modem only)                     *
  5. ;*                                                     *
  6. ;*  CopyRight (C) by Nicholas Poljakov. 1995.          *
  7. ;*                                                     *
  8. ;*******************************************************
  9. .MODEL SMALL
  10.  
  11.  include i_s.inc
  12.  include c:\m61\include\dos.inc
  13.  
  14. public    inbuff, in_cnt, sw_buff, err_cnt, open_type, b_size
  15. public    out_buff, out_cnt, out_full, dcl1, dcl2, err1, lock_send, rcv_exit
  16. public    rcv_off, rcv_seg, base_addr, port_num, save0b, save0c, tsrsize, my_psp
  17. public    blocklt, startblock, ascom, quickexit, nextp, cnt01, fex, cnt00
  18. public    ac_open, ac_opn_02, ac_opn_01, ac_opn_1, ac_opn_5, ac_opn_2, ac_opn_3
  19. public    ac_opn_4, ac_opn_6, ac_opn_7, setcom1, setcom, ac_opn_retry, ac_opn_8
  20. public    ac_opn_9, ac_opn_10, ac_opn_100, ac_opn_101, ac_mdm_act, ac_opn_11
  21. public    ac_exit, ac_opn_exit, ac_close, ac_cls_01, ac_cls_02, ac_cls_03
  22. public    ac_cls_0, ac_cls_exit, ac_send, sndproc, send_cycl, snd_retry, sndexit
  23. public    sendal, send_cycxx, snd_retryx, int6e, int6e_start, popen, int6e_c0
  24. public    int6e_c1, int6e_c2, int6e_c3, int6e_c4, ctl_send, when_ready5, int6e_c5
  25. public    int6e_exit, io_int, next_int, testnext, receive, z_exit, savelt
  26. public    rcvtest0, rcvcycl, rcvtest, callc, io_int_exit, int_exit
  27.  
  28.  
  29. .STACK 10h
  30.  
  31. .DATA
  32.  
  33. inbuff        db 2048 dup (?)
  34. in_cnt        dw 0      ;count of received bytes
  35. sw_buff       db 0
  36. err_cnt       db 0
  37. open_type     db 0      ; 50h - open for PORT
  38. b_size        db 0      ; size of block for transmition
  39. out_buff      dd 0      ; out buffer address
  40. out_cnt       dw 0      ; count of bytes that was send
  41. out_full      dw 0      ; total of send bytes1
  42. dcl1          db 0ah, 0dh
  43.           db 'Async. driver was already installed...$'
  44. dcl2          db 0ah, 0dh
  45.           db 'Async. driver is installed.$'
  46. err1          DB 13,10,"Must have DOS 3.0 or higher",13,10,"$"
  47. lock_send     db 0
  48. rcv_exit      dd 0
  49.               org rcv_exit
  50. rcv_off       dw ?
  51. rcv_seg       dw ?
  52. base_addr     dw 0
  53. port_num      db 0
  54. save0b        db 4 dup (?)
  55. save0c        db 4 dup (?)
  56. tsrsize       dw 0
  57. my_psp        dw 0
  58. BlockLT       dw 0
  59. StartBlock    db 0
  60.  
  61. .CODE
  62. ;
  63. ascom PROC
  64. ;********************************************************
  65. ;*                                                      *
  66. ;*              ASync. COMmunication                    *
  67. ;*                                                      *
  68. ;*  Function: Installation of 6E interrupt handler.     *
  69. ;*            The int 6e routine was disigned to support*
  70. ;*            the COM1 and COM2.                        *
  71. ;*                                                      *
  72. ;********************************************************
  73.       mov  ax, _DATA
  74.       mov  ds, ax
  75.  
  76. ;
  77. ; Calculate Tsrsize
  78. ;
  79.         mov   bx, ss
  80.         mov   ax, es      ; PSP address
  81.         mov   my_psp, ax
  82.         sub   bx, ax
  83.         mov   ax, sp
  84.         mov   cx, 4
  85.         shr   ax, cl      ; convert to paragraphs
  86.         add   bx, ax
  87.         inc   bx          ; one extra paragraph
  88.         mov   tsrsize, bx
  89. ;
  90.         @GetVer           ; Get DOS version
  91.         cmp     al,3      ; Requires DOS 3.0
  92.         jge     NextP
  93.         @ShowStr err1     ; else error and quit
  94. QuickExit:
  95.         @Exit
  96. ;
  97. NextP:
  98.  
  99. ;*
  100. ;* Test if int6e also exist
  101. ;*
  102.  
  103.       mov  ax,356eh
  104.       int  21h
  105.       push es
  106.       pop  ax
  107.       cmp  ax,0
  108.       je   cnt00
  109. cnt01:
  110.       mov  ah,3                ; check function
  111.       int  6eh
  112.       cmp  al,55h              ; is the int6e routine active ?
  113.       jne  cnt00               ; no...
  114. fex:
  115.       mov  dx, offset dcl1
  116.       mov  ah, 9
  117.       int  21h
  118.       jmp  QuickExit
  119. cnt00:
  120.       push ds
  121.       mov  ax, _DATA
  122.       mov  bx, 0ah
  123.       mov  dx, seg int6e
  124.       mov  ds, dx
  125.       mov  word ptr [bx], ax   ; save ds for int6e routine
  126. ;
  127.       mov  dx, seg io_int
  128.       mov  ds, dx
  129.       mov  bx, 0ah
  130.       mov  word ptr [bx], ax   ; save ds for io_int routine
  131.       pop  ds
  132. ;
  133.       push ds                  ;ß«σαá¡∩Ѽ ds
  134.       mov  dx,offset int6e     ;ds:dx π¬áºδóáεΓ ¡á »α«µÑñπαπ
  135.       mov  ax,seg int6e        ;
  136.       mov  ds,ax               ;
  137.       mov  al,6eh              ;¡«¼Ñα óÑ¬Γ«αá ñ½∩ com1
  138.       mov  ah,25h              ;Σπ¡¬µ¿∩ ¿º¼Ñ¡Ñ¡¿∩ óÑ¬Γ«αá
  139.       int  21h                 ;¼Ñ¡∩Ѽ óÑ¬Γ«α »αÑαδóá¡¿∩
  140.       pop  ds
  141. ;
  142.       mov  dx, offset dcl2
  143.       mov  ah, 9
  144.       int 21h
  145. ;
  146.       mov   ax, my_psp
  147.       mov   es, ax
  148.       mov   ax, word ptr es:[2ch]
  149.       mov   es, ax
  150.       mov   ax, 4900h
  151.       int   21h           ; Free the local environment
  152.  
  153.       mov  dx, tsrsize
  154.       mov  ax,3100h
  155.       int  21h
  156. ;
  157.  
  158. ascom ENDP
  159.  
  160. ;*****************************************************
  161. ;*                                                   *
  162. ;*               O P E N  function                   *
  163. ;*                                                   *
  164. ;*   Input  : in AH - function code.                 *
  165. ;*            in AL - subfunction code               *
  166. ;*   Output : Return code. ( 0 - OK; -1 - error)     *
  167. ;*****************************************************
  168.  
  169. ac_open PROC
  170. ;*
  171. ;*  ES:DX -> init_serial structure
  172. ;*
  173.       mov  bx,dx
  174. ;*    Save rcv_exit subroutine entry
  175.       mov  ax, word ptr es:[bx + asc_rcv_exit]
  176.       mov  rcv_off, ax
  177.       mov  ax, word ptr es:[bx + asc_rcv_exit + 2]
  178.       mov  rcv_seg, ax
  179. ;
  180. ;---»«½πτáѼ íẫóδ⌐ áñαÑß com#
  181.       mov  al, byte ptr es:[bx + asc_parity]
  182.       and  al, 0f0h        ; clear right bits
  183.       mov  cl, 4
  184.       ror  al, cl          ; first four bits is com. port number
  185.       mov  port_num, al    ; save com. port number
  186.       cmp  al, 2           ; high COM number (with int support)
  187.       ja   ac_opn_02
  188.       dec  al              ; com. num - 1
  189.       rol  al, 1           ; (com - 1) * 2 - it's displacement in BIOS
  190.       mov  si, 0
  191.       and  ax, 00ffh
  192.       add  si, ax
  193.       push es
  194.       mov  ax,40h          ;es π¬áºδóáÑΓ ¡á «í½áßΓ∞ ñá¡¡δσ bios
  195.       mov  es,ax           ;
  196.       mov  dx,es:[si]      ;»«½πτáѼ íẫóδ⌐ áñαÑß com1
  197.       pop  es
  198.       mov  base_addr, dx
  199.       cmp  dx, 0
  200.       jne  ac_opn_01
  201. ac_opn_02:
  202.       mov  ax, 0ffffh      ; rc = -1 port not present
  203.       jmp  ac_opn_exit
  204. ac_opn_01:
  205. ;---¿¡¿µ¿á½¿º¿απÑ¿ αÑú¿ßΓαδ ñѽ¿Γѽ∩ ß¬«α«ßΓ¿ «í¼Ñ¡á
  206.       add  dx,3            ;π¬áºδóáѼ ¡á αÑú¿ßΓα ¬«¡Γα«½∩ ½¿¡¿¿
  207.       in   al, dx
  208.       jmp  short $+2       ; delay for I/O
  209.       jmp  short $+2       ; delay for I/O
  210.       mov  al,10000000b    ;πßΓá¡áó½¿óáѼ í¿Γ 7
  211.       out  dx,al           ;»«ßδ½áѼ íá⌐Γ
  212.       mov  ax, word ptr es:[bx + asc_speed]
  213.       mov  cx, ax
  214.       dec  dx              ;π¬áºδóáѼ ¡á ßΓáαΦ¿⌐ íá⌐Γ ñѽ¿Γѽ∩
  215.       dec  dx              ;߬«α«ßΓ¿ «í¼Ñ¡á
  216.       in   al, dx
  217.       mov  ax, cx          ; restory ax
  218.       jmp  short $+2       ; delay for I/O
  219.       jmp  short $+2       ; delay for I/O
  220.       mov  al, ah
  221.       out  dx,al           ;»«ßδ½áѼ ßΓáαΦ¿⌐ íá⌐Γ ñѽ¿Γѽ∩
  222.       dec  dx              ;π¬áºδóáѼ ¡á ¼½áñΦ¿⌐ íá⌐Γ ñѽ¿Γѽ∩
  223.       in   al, dx
  224.       jmp  short $+2       ; delay for I/O
  225.       jmp  short $+2       ; delay for I/O
  226.       mov  ax, cx          ; restory ax
  227.       out  dx,al           ;»«ßδ½áѼ ¼½áñΦ¿⌐ íá⌐Γ ñѽ¿Γѽ∩
  228. ;
  229.       cmp  open_type, 50h
  230.       je   ac_opn_2   ; 8 bits in word
  231.       mov  al, byte ptr es:[bx + asc_width]
  232.       cmp  al, 5
  233.       jb   ac_opn_1
  234.       cmp  al,8
  235.       ja   ac_opn_2
  236.       jmp  ac_opn_3
  237. ac_opn_1:
  238.       mov  al, 5
  239.       jmp  ac_opn_3
  240. ac_opn_5:
  241.       mov  ah, 2
  242.       jmp  ac_opn_4
  243. ac_opn_2:
  244.       mov  al, 8
  245. ac_opn_3:
  246.       sub  al, 5
  247. ;---¿¡¿µ¿á½¿º¿απѼ αÑú¿ßΓα ¬«¡Γα«½∩ ½¿¡¿¿
  248.       mov  ah, byte ptr es:[bx + asc_stops]
  249.       cmp  ah, 2
  250.       ja   ac_opn_5
  251. ac_opn_4:
  252.       dec  ah
  253.       mov  cl,2
  254.       rol  ah,cl
  255.       or   al,ah           ; number stop-bits
  256. ;
  257.       mov  ah, byte ptr es:[bx + asc_parity]
  258.       and  ah, 0fh         ; select partity
  259.       cmp  ah, 1
  260.       jne  ac_opn_6
  261.       or   al,00001000b
  262.       jmp  ac_opn_7
  263. ac_opn_6:
  264.       cmp  ah,2
  265.       jne  ac_opn_7
  266.       or   al,00011000b
  267. ac_opn_7:
  268.       add  dx,3            ;π¬áºδóáѼ ¡á αÑú¿ßΓα ¬«¡Γα«½∩ ½¿¡¿¿
  269.       out  dx,al           ;»«ßδ½áѼ ¿¡¿µ¿á½¿ºáµ¿«¡¡«Ñ º¡áτÑ¡¿Ñ
  270. ;
  271. ;---¿¡¿µ¿á½¿º¿απѼ αÑú¿ßΓα αáºαÑΦÑ¡¿∩ »αÑαδóá¡¿∩
  272. ;
  273.       mov  al, byte ptr es:[bx + asc_parity]
  274.       and  al, 0f0h            ; clear right bits
  275.       push dx                  ; save dx
  276.       cmp  al, 10h             ; is it COM1 ?
  277.       je   SetCom1             ; yes... goto SetCom1
  278.       mov  bx, 0bh * 4
  279.       mov  di, offset save0b
  280.       jmp  SetCom
  281. SetCom1:
  282.       mov  bx, 0ch * 4
  283.       mov  di, offset save0c
  284. ;
  285. ;  Set int for COM#
  286. ;
  287. SetCom:
  288.       mov  ax,0
  289.       cli
  290.       push es
  291.       push ds
  292.       push ds
  293.       pop  es
  294.       mov  ds, ax
  295.       mov  si, bx
  296.       mov  cx, 4
  297.       rep movsb
  298.       pop  ds
  299.       pop  es
  300. ;
  301.       push es
  302.       mov  es, ax
  303.       mov  dx,offset io_int    ;ds:dx π¬áºδóáεΓ ¡á »α«µÑñπαπ
  304.       mov  ax,seg io_int       ;int async. processing
  305.       mov  es:[bx], dx
  306.       mov  es:[bx + 2], ax
  307.       pop  es
  308.       sti
  309.       pop  dx
  310. ;
  311. ac_opn_retry:
  312.       dec  dx              ;π¬áºδóáѼ ¡á αÑú¿ßΓα αáºαÑΦÑ¡¿∩
  313.       dec  dx              ;»αÑαδóá¡¿∩
  314.       in   al, dx
  315.       jmp  short $+2       ; delay for I/O
  316.       jmp  short $+2       ; delay for I/O
  317.       cmp  al, 0
  318.       je   ac_opn_8
  319.       inc  dx
  320.       in   al, dx
  321.       inc  dx
  322.       inc  dx
  323.       inc  dx               ; line status
  324.       in   al, dx
  325.       inc  dx               ; modem status
  326.       in   al, dx
  327.       mov  dx, base_addr
  328.       in   al, dx
  329.       inc  dx
  330.       mov  al, 0
  331.       out  dx, al
  332.       inc  dx
  333.       inc  dx
  334.       jmp  ac_opn_retry
  335. ac_opn_8:
  336.       mov  err_cnt, 0
  337.       cli                  ; Disable interrupts
  338.       in   al,21h          ; port 21h, 8259-1 int IMR
  339.       and  al,0E7h
  340.       cmp  port_num, 1     ; COM1 ?
  341.       jne  ac_opn_9        ; no it's COM2
  342.       or   al, 00001000b
  343.       jmp  short ac_opn_10
  344. ac_opn_9:
  345.       or   al, 00010000b
  346. ac_opn_10:
  347.       out  21h,al          ; port 21h, 8259-1 int comands
  348.       jmp  short $+2       ; delay for I/O
  349.       jmp  short $+2       ; delay for I/O
  350.       in   al, 21h
  351.       cmp  port_num, 1     ; is't COM1 ?
  352.       jne  ac_opn_100      ; no it's COM2...
  353.       test al, 00010000b   ; it's COM1
  354.       jz   ac_opn_101
  355.       and  al, 11101111b
  356.       out  21h, al
  357.       jmp  ac_opn_101
  358. ac_opn_100:
  359.       test al, 00001000b
  360.       jz   ac_opn_101
  361.       and  al, 11110111b
  362.       out  21h, al
  363. ac_opn_101:
  364.       mov  al,1            ;páºpÑΦáѼ »αÑαδóá¡¿∩
  365.       out  dx,al           ;»«ßδ½áѼ íá⌐Γ
  366.       inc  dx
  367.       inc  dx
  368.       inc  dx
  369. ac_mdm_act:
  370.       mov  al, 0bh         ; activate modem
  371.       out  dx, al
  372.       inc  dx
  373.       inc  dx
  374.       jmp  short $+2       ; delay for I/O
  375.       jmp  short $+2       ; delay for I/O
  376.       in   al, dx
  377.       dec  dx
  378.       jmp  short $+2       ; delay for I/O
  379.       jmp  short $+2       ; delay for I/O
  380.       in   al, dx
  381.       test al, 0eh
  382.       jz   ac_exit
  383.       test al, 00000001b
  384.       jz   ac_opn_11
  385.       mov  dx, base_addr
  386.       in   al, dx
  387.       jmp  short $+2       ; delay for I/O
  388.       jmp  short $+2       ; delay for I/O
  389.       inc  dx
  390.       in   al, dx
  391.       jmp  short $+2       ; delay for I/O
  392.       jmp  short $+2       ; delay for I/O
  393.       mov  al, 0
  394.       out  dx, al
  395.       jmp  short $+2       ; delay for I/O
  396.       jmp  short $+2       ; delay for I/O
  397.       mov  al, 1
  398.       out  dx, al
  399.       add  dx, 3
  400.       jmp  ac_mdm_act
  401. ac_opn_11:
  402.       dec  dx
  403.       inc  err_cnt
  404.       cmp  err_cnt, 10
  405.       ja   ac_exit
  406.       jmp  ac_mdm_act
  407. ac_exit:
  408.       sti                  ; Enable interrupts
  409.       mov  err_cnt, 0
  410. ;
  411.       mov  ax, 0           ; ret. code
  412. ac_opn_exit:
  413.       ret
  414.  
  415. ac_open ENDP
  416. ;
  417.  
  418. ;*****************************************************
  419. ;*                                                   *
  420. ;*               C L O S E  function                 *
  421. ;*                                                   *
  422. ;*   Input  : in AH - function code.                 *
  423. ;*   Output : Return code. ( 0 - OK; -1 - error)     *
  424. ;*****************************************************
  425. ac_close PROC
  426. ;*
  427. ;* Close subroutine
  428. ;*
  429. ;* In al port number (1 or 2)
  430. ;*
  431.       cmp  al, port_num
  432.       je   ac_cls_01
  433.       jmp  ac_cls_exit
  434. ac_cls_01:
  435.       cmp  al, 1
  436.       jne  ac_cls_02
  437.       mov  di, 0bh * 4
  438.       mov  si, offset save0b
  439.       jmp  short ac_cls_03
  440. ac_cls_02:
  441.       mov  di, 0ch * 4
  442.       mov  si, offset save0c
  443. ac_cls_03:
  444.       mov  ax, 0
  445.       push es
  446.       mov  es, ax
  447.       mov  cx, 4
  448.       cli
  449.       rep movsb
  450.       pop  es
  451. ;---»«½πτáѼ íẫóδ⌐ áñαÑß
  452.       mov  dx,base_addr    ;»«½πτáѼ íẫóδ⌐ áñαÑß
  453.       cmp  dx,0
  454.       jne  ac_cls_0
  455.       jmp  ac_cls_exit
  456. ;
  457. ac_cls_0:
  458.       inc  dx
  459.       mov  al,0            ;ºá»pÑΘáѼ »αÑαδóá¡¿∩
  460.       out  dx,al           ;»«ßδ½áѼ íá⌐Γ
  461. ac_cls_exit:
  462.       sti
  463.       ret
  464. ac_close ENDP
  465. ;
  466.  
  467. ;*****************************************************
  468. ;*                                                   *
  469. ;*               S E N D  function                   *
  470. ;*                                                   *
  471. ;*   Input  : in AH - function code.                 *
  472. ;*            in es:dx pointer to block;             *
  473. ;*            in cx - length of block                *
  474. ;*                                                   *
  475. ;*   Output : Return code. ( 0 - OK; -1 - error)     *
  476. ;*****************************************************
  477. ac_send PROC
  478.        and  cx, cx                ; is length valid ?
  479.        jnz  SndProc
  480.        cmp  cx, 2048
  481.        jbe  SndProc
  482.        jmp  SndExit
  483.  
  484. SndProc:
  485.        mov  lock_send, 0          ; send no locking
  486.        mov  bx, offset out_buff
  487.        mov  word ptr [bx], dx     ; save offset and
  488.        mov  word ptr [bx + 2], es ; segment of out buffer
  489.        mov  out_full, cx          ; save out counter
  490.        mov  out_cnt, 0            ; initial value
  491.        mov  si, dx
  492.        sti               ; enable int.'s
  493.        mov  al, 65h      ; send StartBlock indicator
  494.        call SendAL
  495.        jmp  short $+2    ; delay for I/O
  496.        jmp  short $+2    ; delay for I/O
  497.        jmp  short $+2    ; delay for I/O
  498.        jmp  short $+2    ; delay for I/O
  499.        jmp  short $+2    ; delay for I/O
  500.        jmp  short $+2    ; delay for I/O
  501.  
  502.        mov  al, cl       ; send low byte of length
  503.        call SendAl
  504.        mov  al, ch       ; send high byte of length
  505.        call SendAl
  506.        jmp  short $+2    ; delay for I/O
  507.        jmp  short $+2    ; delay for I/O
  508.        jmp  short $+2    ; delay for I/O
  509.        jmp  short $+2    ; delay for I/O
  510.        jmp  short $+2    ; delay for I/O
  511.        jmp  short $+2    ; delay for I/O
  512.  
  513. send_cycl:
  514.        cmp  lock_send, 0 ; enable send ?
  515.        jne  send_cycl    ; that must be replaced !!!
  516.        mov  ah, byte ptr es:[si]
  517.        add  dx, 5
  518. snd_retry:
  519.        in   al,dx
  520.        test al,00100000b ; ready to send ?
  521.        jz   snd_retry
  522.        sub  dx, 5
  523.        mov  al, ah
  524.        out  dx, al
  525.        dec  out_full
  526.        inc  out_cnt
  527.        inc  si           ; next byte
  528. ;
  529.        loop send_cycl
  530. ;
  531. SndExit:
  532.        ret
  533. ac_send ENDP
  534.  
  535. ;***************************************************
  536. ;*          Send Byte from AL                      *
  537. ;*                                                 *
  538. ;*  Function : Send on async. port one byte.       *
  539. ;*  Input    : In AL byte for send.                *
  540. ;*                                                 *
  541. ;***************************************************
  542. SendAL PROC
  543.        push ax
  544.        mov  dx, base_addr
  545. send_cycXX:
  546.        cmp  lock_send, 0 ; enable send ?
  547.        jne  send_cycXX   ; that must be replaced !!!
  548.        add  dx, 5
  549. snd_retryX:
  550.        in   al,dx
  551.        test al,00100000b ; ready to send ?
  552.        jz   snd_retryX
  553.        sub  dx, 5
  554.        pop  ax
  555.        out  dx, al
  556.        ret
  557. SendAL ENDP
  558.  
  559. ;*****************************************************
  560. ;*                                                   *
  561. ;*              Int 6E handler                       *
  562. ;*                                                   *
  563. ;*   Input  : in AH - function code.                 *
  564. ;*            (and for send function )               *
  565. ;*            in ds:dx pointer to block;             *
  566. ;*            in cx - length of block                *
  567. ;*                                                   *
  568. ;*   Output : Return code. ( 0 - OK; -1 - error)     *
  569. ;*****************************************************
  570.  
  571. int6e PROC  far
  572.       push bx
  573.       push cx
  574.       push dx
  575.       push si
  576.       push di
  577.       push ds
  578.       push es
  579.       push bp
  580.  
  581.       mov  bp, sp
  582. ;
  583.       jmp  int6e_start
  584.       dw 0
  585. int6e_start:
  586.       push ds
  587.       pop  es  ; change ds and es
  588.       push ax
  589.       mov  bx, 0ah
  590.       mov  ax, word ptr cs:[bx]
  591.       mov  ds, ax       ; restory ds
  592.       pop  ax
  593.       cmp  ah,0         ; "open" function ?
  594.       jne  int6e_c0
  595.       mov  open_type, al ; Open for "PORT"
  596.       cmp  al, 50h      ; open for PORT ?
  597.       je   Popen
  598.       mov  ax, 0ffffh   ; bad return code;
  599.       jmp  int6e_exit
  600. Popen:
  601.       call ac_open
  602.       jmp  int6e_exit
  603. int6e_c0:
  604.       cmp  ah,1         ; "close" function ?
  605.       jne  int6e_c1
  606.       call ac_close
  607.       jmp  int6e_exit
  608. int6e_c1:
  609.       cmp  ah,2         ; "send" function ?
  610.       jne  int6e_c2
  611.       call ac_send
  612.       jmp  int6e_exit
  613. int6e_c2:
  614.       cmp  ah,3         ; "test" function ?
  615.       jne  int6e_c3
  616.       mov  al,55h
  617. int6e_c3:
  618.       cmp  ah,4         ; "Get stat" function ?
  619.       jne  int6e_c5
  620.       cmp  al, 0        ; Send status ?
  621.       jne  int6e_c4
  622.       mov  ax, out_full ; Rest bytes for send
  623.       jmp  int6e_exit
  624. int6e_c4:
  625.       cmp  al, 2        ; Send xoff ?
  626.       jne  int6e_exit
  627.       mov  out_full, 0
  628.       mov  al, 19h
  629. ctl_send:
  630.       mov  dx, base_addr
  631.       add  dx, 5        ; line status
  632. when_ready5:
  633.       in   al, dx
  634.       test al, 00100000b ; ready to send ?
  635.       jz   when_ready5   ; retry
  636.       sub  dx, 5
  637.       out  dx, al
  638.       jmp  int6e_exit
  639. int6e_c5:
  640.       cmp  al, 3        ; Send xon ?
  641.       jne  int6e_exit
  642.       mov  out_full, 0
  643.       mov  al, 17h      ; xon
  644.       jmp  ctl_send
  645. ;
  646. int6e_exit:
  647.       pop  bp
  648.       pop  es
  649.       pop  ds
  650.       pop  di
  651.       pop  si
  652.       pop  dx
  653.       pop  cx
  654.       pop  bx
  655.       iret
  656. int6e ENDP
  657.  
  658.  
  659. ;*****************************************************
  660. ;*                                                   *
  661. ;*           Handler for I/O interrupt               *
  662. ;*                                                   *
  663. ;*****************************************************
  664.  
  665. io_int PROC   far
  666.       push ax
  667.       push bx
  668.       push cx
  669.       push dx
  670.       push si
  671.       push di
  672.       push ds
  673.       push es
  674. ;
  675.       jmp  short $ + 4
  676.       dw   0
  677.       mov  bx, 0ah
  678.       mov  ax, word ptr cs:[bx]
  679.       mov  ds, ax      ; restory DS
  680. ;
  681. Next_int:
  682.       mov  dx, base_addr       ;íẫóδ⌐ áñαÑß
  683.       add  dx, 2               ; int. identification
  684.       in   al, dx
  685.       add  dx, 3               ; line status
  686.       in   al, dx
  687.       test al, 00001110b       ; errors ?
  688.       jz   TestNext
  689.       jmp  io_int_exit
  690. TestNext:
  691.       test al, 00000001b       ; was byte received ?
  692.       jnz  receive
  693.       jmp  io_int_exit
  694. ;
  695. ;
  696. ;    Receive subroutine
  697. ;
  698. ;
  699. receive:
  700.       mov  si, offset inbuff
  701.       xor  bx, bx
  702.       sub  dx, 4
  703.       xor  ax, ax
  704.       out  dx, al         ; disable Com# interrupt
  705.       dec  dx
  706.       in   al, dx
  707.       cmp  StartBlock, 65h
  708.       je   SaveLt
  709.       mov  StartBlock, al
  710. Z_exit:
  711.       inc  dx
  712.       mov  al, 1          ; enable RECEIVE interrupt
  713.       out  dx, al
  714.       jmp  io_int_exit
  715. SaveLt:
  716.       mov  byte ptr BlockLT, al ; save low byte of length
  717.       add  dx,5           ;π¬áºδóáѼ ¡á αÑú¿ßΓα ßΓáΓπßá ½¿¡¿¿
  718. RcvTest0:
  719.       in   al,dx          ;»«½πτáѼ íá⌐Γ ßΓáΓπßá
  720.       test al,00000001b   ;»α«óÑα∩Ѽ »«½πτÑ¡δ ½¿ ñá¡¡δÑ
  721.       jz   RcvTest0
  722.       sub  dx, 5
  723.       in   al,dx          ;τ¿ΓáѼ »«½πτÑ¡¡δ⌐ ß¿¼ó«½
  724.       mov  byte ptr BlockLT + 1, al ; save high byte of length
  725.  
  726.       mov  cx, BlockLT
  727.       and  cx, cx
  728.       jnz  RcvCycl
  729.       mov  StartBlock, 0
  730.       jmp  Z_exit
  731.  
  732. RcvCycl:
  733.       add  dx,5           ;π¬áºδóáѼ ¡á αÑú¿ßΓα ßΓáΓπßá ½¿¡¿¿
  734. RcvTest:
  735.       in   al,dx          ;»«½πτáѼ íá⌐Γ ßΓáΓπßá
  736.  
  737. ;     test al,00011110b   ;»α«óÑα∩Ѽ ¡á «Φ¿í¬π
  738. ;     jnz  error_routine  ;Ñß½¿ ñá, Γ« ¡á «íαáí«Γ¬π «Φ¿í¬¿
  739.  
  740.       test al,00000001b   ;»α«óÑα∩Ѽ »«½πτÑ¡δ ½¿ ñá¡¡δÑ
  741.       jz   RcvTest
  742.       sub  dx, 5
  743.       in   al,dx          ;τ¿ΓáѼ »«½πτÑ¡¡δ⌐ ß¿¼ó«½
  744.       mov  byte ptr [si + bx], al
  745.       inc  bx
  746.  
  747.       loop RcvCycl
  748.       mov  StartBlock, 0
  749. ;*
  750. ;* Block ready. Call EXIT routine
  751. ;*
  752.       mov  cx, bx
  753.       mov  dx, si
  754. CallC:
  755. ;
  756.       push dx   ; call
  757.       push ds   ;   with "C"
  758.       push cx   ;      convensions
  759.       mov  ax,  2
  760.       pushf             ; Call "_interrupt" function
  761.       call rcv_exit
  762.       add  sp, 6
  763. ;
  764.       mov  b_size, 0    ; reset size of buffer
  765.  
  766.       mov  dx, base_addr
  767.       inc  dx
  768.       mov  al, 1
  769.       out  dx, al       ; enable RECEIVE interrupt
  770.  
  771. io_int_exit:
  772.       mov  dx,base_addr  ;íẫóδ⌐ áñαÑß
  773.       inc  dx            ;π¬áºδóáѼ ¡á αÑú¿ßΓα ¿ñÑ¡Γ¿Σ¿¬áµ¿¿
  774.       inc  dx            ;»αÑαδóá¡¿∩
  775.       in   al,dx         ;τ¿ΓáѼ Ñú« º¡áτÑ¡¿Ñ
  776.       test al,1          ;»α«óÑα∩Ѽ í¿Γ 1 (interrupt pending)
  777.       jnz  Int_exit
  778.       jmp  Next_int      ;Ñß½¿ «¡ πßΓá¡«ó½Ñ¡, Γ« ¡á ¡áτὫ
  779.  
  780. Int_exit:
  781.       mov  al, 20h
  782.       out  20h, al
  783. ;
  784.       pop  es
  785.       pop  ds
  786.       pop  di
  787.       pop  si
  788.       pop  dx
  789.       pop  cx
  790.       pop  bx
  791.       pop  ax
  792.       iret
  793. io_int ENDP
  794. ;
  795.       END ascom
  796.